package haoyc.handler;

import haoyc.utils.MarshallingCodeCFactory;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * @author Memory
 * @version 1.0
 * @date 2021/11/22
 */
public class ServerInitializer extends ChannelInitializer<NioSocketChannel> {
    @Override
    protected void initChannel(NioSocketChannel ch) {
        try {
            ch.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());
            ch.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());
            ch.pipeline().addLast("logging", new LoggingHandler(LogLevel.INFO));
            ch.pipeline().addLast("login handler", new LoginHandler());
            ch.pipeline().addLast("response handler", new ResponseHandler());
            ch.pipeline().addLast("operator handler", new OperatorHandler());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
